package com.clhbolg.util;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.clhbolg.domain.UserInfo;
import com.clhbolg.model.dto.WebsiteConfigDTO;
import com.clhbolg.model.vo.request.UserInfoVO;
import com.clhbolg.service.IWebsiteConfigService;
import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.stereotype.Component;

/**
 * @Author cailinhu
 * @Description 各种用户类型构建
 * @Date 2023/3/2 14:47
 * @Version 1.0
 */
@Component
public class UserBuilderUtil {

  public UserBuilderUtil(IWebsiteConfigService websiteConfigService){
        this.websiteConfigService=websiteConfigService;
    }

    private static IWebsiteConfigService websiteConfigService;

    public static UserInfo builderUserInfo(SysUser sysUser){
        UserInfo userInfo = new UserInfo();
        userInfo.setId(sysUser.getUserId());
        userInfo.setEmail(sysUser.getEmail());
        userInfo.setNickname(sysUser.getNickName());
        userInfo.setIntro(sysUser.getRemark());//描述
        //设置默认头像
        WebsiteConfigDTO websiteConfig = websiteConfigService.getWebsiteConfig();
        userInfo.setAvatar(StrUtil.isNotEmpty(sysUser.getAvatar())?sysUser.getAvatar():websiteConfig.getUserAvatar());
        userInfo.setIsDisable(StrUtil.isNotEmpty(sysUser.getStatus())?Integer.valueOf(sysUser.getStatus()):0);
        userInfo.setIsSubscribe(0); //默认未订阅
        return userInfo;
    }


    public static SysUser builderSysUser(UserInfoVO infoVO){
        SysUser sysUser = new SysUser();
        sysUser.setNickName(infoVO.getNickname());
        sysUser.setRemark(infoVO.getIntro());
        return sysUser;
    }


    public static UserInfo builderUserInfo(UserInfoVO infoVO){
        UserInfo convert = Convert.convert(UserInfo.class, infoVO);
        return convert;
    }


}
